package paging

//分页数据组装
func PageUtil(page int, pageSize int, lastPage bool, list interface{}) Page {
	totalPage := page
	if !lastPage {
		totalPage ++
	}
	return Page{
		Page:      page,
		PageSize:  pageSize,
		TotalPage: totalPage,
		FirstPage: page == 1,
		LastPage:  lastPage,
		List:      list,
	}
}

//分页数据组装
func PageUtilWithCount(count int, page int, pageSize int, list interface{}) Page {
	tp := count / pageSize
	if count%pageSize > 0 {
		tp = count/pageSize + 1
	}
	return Page{
		Page:       page,
		PageSize:   pageSize,
		TotalPage:  tp,
		TotalCount: count,
		FirstPage:  page == 1,
		LastPage:   page == tp,
		List:       list,
	}
}
